package com.awccis.admin.service.impl;

import com.awccis.admin.dao.AdverDao;
import com.awccis.admin.model.adver.AdverBean;
import com.awccis.admin.model.adver.AdverCombineBean;
import com.awccis.admin.model.adver.AdverInfoBean;
import com.awccis.admin.model.adver.CurrentLogoPathBean;
import com.awccis.admin.service.AdverService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author: txp
 * @date: 2018/5/7 on 下午9:07
 * @since: 1.0
 * @description:
 **/
@Service("adverServiceImpl")
public class AdverServiceImpl implements AdverService {
    
    @Resource
    AdverDao adverDao;
    
    /**
     * 添加广告信息
     *
     * @param adverCombineBean
     * @return 执行结果
     */
    @Override
    public boolean insertAdverInfo(AdverCombineBean adverCombineBean) throws NullPointerException {
        boolean b1 = adverDao.insertLogoInfo(adverCombineBean.getLogoBean()) == 1;
        boolean b2 = false;
        if (b1) {
            AdverBean adverBean = adverCombineBean.getAdverBean();
            adverBean.setLogoId(adverCombineBean.getLogoBean().getLogoId());
            b2 = adverDao.insertAdverInfo(adverBean) == 1;
        }
        return b2;
    }

    /**
     * 查询所有广告信息
     *
     * @return 所有广告信息的列表
     */
    @Override
    public List<AdverInfoBean> selectAllAdverInfo() {
        return adverDao.selectAdverInfo();
    }

    /**
     * 删除广告信息
     *
     * @param hashMap adverId， logoId
     * @return 执行结果
     */
    @Override
    public boolean deleteAdverInfo(HashMap<String, Integer> hashMap) {
        String logoId = "logoId";
        String adverId = "adverId";
        boolean b1 = false;
        boolean b2 = false;
        if (hashMap.get(logoId) != null && hashMap.get(adverId) != null) {
            b1 = adverDao.deleteAdverInfo(hashMap.get(adverId)) == 1;
            b2 = adverDao.deleteLogoInfo(hashMap.get(logoId)) == 1;
        }
        return b1 & b2;
    }

    /**
     * 更改九张图片的的当前logo位置
     *
     * @param list list
     * @return true or false
     */
    @Override
    public boolean updateNowLogoPath(List<CurrentLogoPathBean> list) {
        boolean flag = false;
        for (CurrentLogoPathBean currentLogoPathBean : list) {
            flag = adverDao.updateLogoLocation(currentLogoPathBean) == 1;
        }
        return flag;
    }
}
